package com.zhongkun.datahome.core.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.apache.ibatis.type.Alias;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Author: MinKun
 * @Date: Created in 2025/5/7
 * @Description:
 */
@Data
@Alias("MiniProgramDataSetting2")
@TableName("mini_program_data_setting")
public class MiniProgramDataSetting implements Serializable {
    private static final long serialVersionUID = 1L;

    private String iconUrl;

    private String name;

    private Long parentId;

    /** 0:末级类目 1：非末级类目 */
    private Integer level;

    private Integer sort;

    /**
     * @see  com.zhongkun.datahome.common.enums.DataSettingLinkTypeEnum
     */
    private String linkType;

    @TableField(exist = false)
    private List<MiniProgramDataSetting> children;

    /**
     * 自增主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;
    /**
     * 创建者
     */
    @TableField(fill = FieldFill.INSERT)
    private Long createBy;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    private Date createTime;
    /**
     * 更新者
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateBy;
    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.UPDATE)
    private Date updateTime;
    /**
     * 删除标志（0代表存在 1代表删除）
     */
    @TableLogic
    private Integer delFlag;
    /**
     * 商户id
     */
    @TableField(fill = FieldFill.INSERT)
    private Long tenantId;

    public static MiniProgramDataSetting of(String name, String iconUrl, Integer sort, String linkType, Long tenantId) {
        MiniProgramDataSetting dataSetting = new MiniProgramDataSetting();
        dataSetting.setName(name);
        dataSetting.setIconUrl(iconUrl);
        dataSetting.setSort(sort);
        dataSetting.setLevel(0);   // 末级类目
        dataSetting.setLinkType(linkType);
        dataSetting.setTenantId(tenantId);
        return dataSetting;
    }
}
